//
//  AppDelegate.m
//  敢唆嘛!
//
//  Created by 教主 on 15/11/23.
//  Copyright © 2015年 zms. All rights reserved.
//

#define BombKey @"5219622511b6d859c573c8554bbe8d77"
#define ShareKey @"cb549924f9c7"

#import "GsmDelegate.h"
#import "GsmNavigationController.h"
#import "MainController.h"
#import "Define.h"
#import "StartController.h"

@interface GsmDelegate ()

@end

@implementation GsmDelegate

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
    return [ShareSDK handleOpenURL:url wxDelegate:self];
}

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *) sourceApplication annotation:(id)annotation
{
    return [ShareSDK handleOpenURL:url sourceApplication:sourceApplication annotation:annotation wxDelegate:self];
}

// 添加分享
- (void)shareSDK
{
    [ShareSDK registerApp:ShareKey];//字符串api20为您的ShareSDK的AppKey
    
    //微信登陆的时候需要初始化
    [ShareSDK connectWeChatWithAppId:@"wx4c525b12d0f1714f"
                           appSecret:@"d4624c36b6795d1d99dcf0547af5443d"
                           wechatCls:[WXApi class]];
    
//    //添加腾讯微博应用 注册网址 http://dev.t.qq.com
//    [ShareSDK connectTencentWeiboWithAppKey:@"1104898087"
//                                  appSecret:@"5dUp5qyfni0qAy70"
//                                redirectUri:@"http://www.sharesdk.cn"];
    
    //添加QQ空间应用  注册网址  http://connect.qq.com/intro/login/
    [ShareSDK connectQZoneWithAppKey:@"1104991318"
                           appSecret:@"3lmoUlqyivn52eaI"
                   qqApiInterfaceCls:[QQApiInterface class]
                     tencentOAuthCls:[TencentOAuth class]];
    
    // QQ
    [ShareSDK connectQQWithAppId:@"1104991318" qqApiCls:[QQApiInterface class]];
}

// 初始化bomb
- (void)bombRegister
{
    // 设置自己应用的key
    [Bmob registerWithAppKey:BombKey];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    // 初始化bmob
    [self bombRegister];
    
    // 添加分享调用
    [self shareSDK];
    
    // 创建window frame和全屏大小
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    
    // 给window一个背景颜色
    self.window.backgroundColor = [UIColor whiteColor];
    
    // 进入判断启动页面 给本地缓存存入一个BOOL值 来判断是否是第一次进入APP
    BOOL isStart = [[NSUserDefaults standardUserDefaults] boolForKey:@"isStart"];
    if (isStart)
    {
        // nav控制器
        GsmNavigationController *gsmNav = [[GsmNavigationController alloc] initWithRootViewController:[[MainController alloc] init]];
        self.window.rootViewController = gsmNav;
    }
    else
    {
        StartController *startVc = [[StartController alloc] init];
        self.window.rootViewController = startVc;
    }
    
    // 显示window
    [self.window makeKeyAndVisible];
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
